// DlgExportAnimate.cpp : implementation file
//

#include "stdafx.h"
#include "ansieditor.h"
#include "DlgExportAnimate.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgExportAnimate dialog


CDlgExportAnimate::CDlgExportAnimate(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgExportAnimate::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgExportAnimate)
	//}}AFX_DATA_INIT
}


void CDlgExportAnimate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgExportAnimate)
	DDX_Control(pDX, IDCANCEL, m_btnCancel);
	DDX_Control(pDX, IDPREV, m_btnPrev);
	DDX_Control(pDX, IDNEXT, m_btnNext);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgExportAnimate, CDialog)
	//{{AFX_MSG_MAP(CDlgExportAnimate)
	ON_BN_CLICKED(IDPREV, OnBtnPrev)
	ON_BN_CLICKED(IDNEXT, OnBtnNext)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_WizardButtonSetFocus, OnWizardButtonSetFocus)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgExportAnimate message handlers

BOOL CDlgExportAnimate::OnInitDialog()
{
	CDialog::OnInitDialog();
	gpApp->m_mui.UpdateDialog(this, IDD);

	CRect rect;
	m_btnPrev.GetWindowRect(rect);
	ScreenToClient(rect);
	m_btnNext.MoveWindow(rect.right, rect.top, rect.Width(), rect.Height());

	m_arrPage.Add(&m_pageAniType);
	m_arrPage.Add(&m_pageAniTypeDelay);
	m_arrPage.Add(&m_pageAniTypeFrame);

	GetClientRect(rect);
	int nCount = m_arrPage.GetSize();
	for(int n = 0; n < nCount; n++)
	{
		CWizardPage *pDlg = m_arrPage.GetAt(n);
		pDlg->m_pData = &m_data;
		pDlg->Create(this);
		pDlg->MoveWindow(rect.left, 5, rect.right, rect.bottom - 60);
		
	}
	m_pageAniTypeDelay.m_pPrevPage = &m_pageAniType;
	m_pageAniTypeFrame.m_pPrevPage = &m_pageAniType;
	m_pageAniType.p_PageAniTypeDelay = &m_pageAniTypeDelay;
	m_pageAniType.p_PageAniTypeFrame = &m_pageAniTypeFrame;

	m_pCurPage = &m_pageAniType;
	m_pCurPage->ActivatePage();

	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgExportAnimate::OnOK() 
{
	if(m_btnNext.IsWindowEnabled())
	{
		OnBtnNext();
	}
	else if(m_btnPrev.IsWindowEnabled())
	{
		OnBtnPrev();
	}
}

void CDlgExportAnimate::FinishWizard()
{
	CWaitCursor wc;
	
	if(m_pCurPage->SendMessage(WM_IfReturnOnFinish))
	{
		// return to firstpage
	}
	else
	{
		m_data.SaveState();
		CDialog::OnOK();
	}
}

void CDlgExportAnimate::OnBtnPrev() 
{
	m_pCurPage->ShowWindow(SW_HIDE);
	m_pCurPage = m_pCurPage->m_pPrevPage;
	if(!m_pCurPage->m_pPrevPage)
	{
		m_btnPrev.EnableWindow(FALSE);
		SendMessage(WM_NEXTDLGCTL);
	}
	m_pCurPage->ActivatePage();
}

void CDlgExportAnimate::OnBtnNext() 
{
	if(!m_pCurPage->ValidatePage())
	{
		return;
	}
	
	if(m_pCurPage->IsLastPage())
	{
		FinishWizard();
		return;
	}

	m_btnCancel.EnableWindow(FALSE);
	m_btnPrev.EnableWindow(FALSE);
	m_btnNext.EnableWindow(FALSE);
	
	CWaitCursor wc;
	m_pCurPage->ShowWindow(SW_HIDE);
	m_pCurPage = m_pCurPage->m_pNextPage;
	m_pCurPage->ActivatePage();

	m_btnCancel.EnableWindow(TRUE);
}

LRESULT CDlgExportAnimate::OnWizardButtonSetFocus(WPARAM wParam, LPARAM lParam)
{
	m_pCurPage->SaveFocus((HWND)wParam);
	return 0;
}

void CDlgExportAnimate::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	dc.SetBkMode(TRANSPARENT);
	dc.TextOut(100, 100, gpApp->m_mui.LoadString(IDS_LOADING_WZPAGE));
}

void CDlgExportAnimate::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}
